package com.whut.entryservice.controller;

import com.whut.clcommon.entity.Result;
import com.whut.entryservice.domain.dto.CancelEntryDTO;
import com.whut.entryservice.domain.dto.EntryDTO;
import com.whut.entryservice.domain.vo.AllEntryVO;
import com.whut.entryservice.domain.vo.EntryVO;
import com.whut.entryservice.service.IEntryService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 部落联赛报名
 * @Author: Zonghe Wang
 * @Date: 2025/5/3 21:58
 */
@RestController
@RequestMapping("/entry")
@RequiredArgsConstructor
public class EntryController {

    private final IEntryService entryService;

    /**
     * 部落联赛报名接口
     * @param entryDTO
     * @return
     */
    @PostMapping
    public Result entry(@RequestBody EntryDTO entryDTO) {
        return entryService.entry(entryDTO);
    }

    @GetMapping
    public Result<AllEntryVO> getAllEntryByBigClanId(@RequestParam("bigClanId") Long bigClanId) {
        AllEntryVO allEntryVO = entryService.getAllEntry(bigClanId);
        return Result.success(allEntryVO);
    }

    /**
     * 根据部落id查询报名信息
     * @param cid
     * @return
     */
    @GetMapping("/{cid}")
    public Result<EntryVO> getEntryByCid(@PathVariable String cid) {
        EntryVO entryVO = entryService.selectEntryByClanNo(cid);
        return Result.success(entryVO);
    }

    /**
     * 取消报名
     * @param cancelEntryDTO
     * @return
     */
    @DeleteMapping
    public Result cancelEntry(@RequestBody CancelEntryDTO cancelEntryDTO) {
        entryService.cancelEntry(cancelEntryDTO);
        return Result.success();
    }

}
